package com.magina.project.quartz.base;


import com.magina.project.quartz.entity.ScheduleDataBean;
import com.magina.project.quartz.service.JobService;
import com.magina.project.quartz.util.SpringUtil;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import java.util.Date;

@Slf4j
public class HandTaskJob implements Job{

    private JobService jobService;


    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {

        try{
            log.info("start quartz job time = {}",new Date());
            JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
            String id = null == jobDataMap.get("taskId") ? null : jobDataMap.get("taskId").toString();
            ScheduleDataBean dataBean = null == jobDataMap.get("dataBean") ? null : (ScheduleDataBean) jobDataMap.get("dataBean");
            log.info("execute  quartz param: id= {},dataBean = {}",id,dataBean);
            if(null == jobService){
                jobService = SpringUtil.getBean(JobService.class);
            }
            jobService.excuteJobData(dataBean);

            log.info("exam handStatus quartz job done,id={},dataBean={}",id,dataBean);
        }catch (Exception e){
            throw new JobExecutionException(e);
        }
    }



}
